﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A73new关键字覆盖父类成员_了解
{
    class Program
    {
        static void Main(string[] args)
        {
            A a = new B();
            a.Fun();//覆盖,通过A调用A的,通过B调用B的;
            a.Test();//重写永远调用子类的方法

            Studen s = new Studen("张三");
            Console.WriteLine(s);
        }
    }
    class A
    {
        public int x;
        public void Fun() 
        {
            Console.WriteLine("AFun");
        }

        public virtual void Test() 
        {
            Console.WriteLine("ATest");
        }
    }
    class B:A
    {
        public new  int  x;
        public new void Fun()//覆盖
        {
            Console.WriteLine("BFun");
        }

        public override void Test()
        {
            Console.WriteLine("BTest");
            
        }
    }

    class Studen
    {
        public string name;

        public Studen(string name)
        {
            this.name = name;
        }
        public override string ToString()
        {
            return name;
        }
    }
    
}
